/**********************************************************************
  The MIT License (MIT)
  Copyright (c) 2012 sunriseyuen

  Permission is hereby granted, free of charge, to any person obtaining
  a copy of this software and associated documentation files
  (the "Software"), to deal in the Software without restriction,
  including without limitation the rights to use, copy, modify, merge,
  publish, distribute, sublicense, and/or sell copies of the Software,
  and to permit persons to whom the Software is furnished to do so,
  subject to the following conditions:

  The above copyright notice and this permission notice shall be included
  in all copies or substantial portions of the Software.

  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
  TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH
  THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 ***********************************************************************/

#define _DEF_CCY_CODE
#define _ZZDEBUG
#define _PROJ_DC

#region Using directives
using System;
using System.Text;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;

using Muki.Framework.Util;
using Muki.Framework.Business;
using Muki.Framework;
using Muki.UserDefine;
using Muki.Entity;
using Dot.StreamObject;

#endregion

namespace Muki.UserPanel
{
	public class UID08025BM:BLogic
	{
		public UID08025BM()
		{
			objDefault.UID_CODE    ="UID08025B";
		}

		public void Initialize()
		{
			objDefault.ZZLOGON_SSD = this.ZZLOGON_SSD;
			objDefault.Trans       = this.Trans;
			objDefault.ZZLOGON_ID  = this.ZZLOGON_ID;

			_Convert.ZZLOGON_SSD = this.ZZLOGON_SSD;
			_Convert.Trans       = this.Trans;

			_DataPermission.ZZLOGON_SSD = this.ZZLOGON_SSD;
			_DataPermission.Trans       = this.Trans;
			_DataPermission.TABLE_NAME  = "TMRDTLM";
			_DataPermission.ZZLOGON_ID  = this.ZZLOGON_ID;
			_DataPermission.DataAccessRight();

			_DocsPermission.ZZLOGON_SSD  = this.ZZLOGON_SSD;
			_DocsPermission.Trans        = this.Trans;

			_Setting.ZZLOGON_ID = this.ZZLOGON_ID;
			_Setting.Trans      = this.Trans;

		}

		public UID08025BE Verify(UID08025BE _Entity)
		{

						_Entity.TM_DT=_Entity.TM_DT.Trim();

					if (Util.IsNullOrEmpty(_Entity.ITEM_NO))
					{
						_Entity.Exceptions.Add(new LogisticException("ITEM_NO","DataMiss"));
					}

					if (Util.IsNullOrEmpty(_Entity.TRANS_QTY))
					{
						_Entity.Exceptions.Add(new LogisticException("TRANS_QTY","DataMiss"));
					}

					if (Util.IsNullOrEmpty(_Entity.REFX_NO))
					{
						_Entity.Exceptions.Add(new LogisticException("REFX_NO","DataMiss"));
					}

				// Relation TMRHDTM
			if (!Util.IsNullOrEmpty(_Entity.TM_NO))
			{
			objRetrieveEntity=new CriteriaRetrieve(typeof(TMRHDTMEntity));//仓库转移单主节
			objRetrieveEntity.Top=1;

			objCondition=objRetrieveEntity.NewCondition();
			objCondition.Equals("TM_NO",_Entity.TM_NO);
				_DataPermission.TABLE_NAME="TMRHDTM";
				_DataPermission.AccessCondition(objCondition);
			objEntityContainer=this.Trans.RetrieveEntitys(objRetrieveEntity);

			if (objEntityContainer.Count==0)
			{
				_Entity.Exceptions.Add(new LogisticException("TM_NO","DataNotFd",_Entity.TM_NO));
			}else{

					TMRHDTMEntity objVTMRHDTMEntity=(TMRHDTMEntity)objEntityContainer[0];
					if (objVTMRHDTMEntity.Verified)
					{
						 _Entity.TM_NO=objVTMRHDTMEntity.TM_NO;

					}else{
						_Entity.Exceptions.Add(new LogisticException("TM_NO","DataNotFd",_Entity.TM_NO));
					}
			}
			}
//TMRHDTM

				// Relation PARTBLM
			if (!Util.IsNullOrEmpty(_Entity.ITEM_NO))
			{
			objRetrieveEntity=new CriteriaRetrieve(typeof(PARTBLMEntity));//物料资料主表
			objRetrieveEntity.Top=1;

			objCondition=objRetrieveEntity.NewCondition();
			objCondition.Equals("ITEM_NO",_Entity.ITEM_NO);
				_DataPermission.TABLE_NAME="PARTBLM";
				_DataPermission.AccessCondition(objCondition);
			objEntityContainer=this.Trans.RetrieveEntitys(objRetrieveEntity);

			if (objEntityContainer.Count==0)
			{
				_Entity.Exceptions.Add(new LogisticException("ITEM_NO","DataNotFd",_Entity.ITEM_NO));
			}else{

					PARTBLMEntity objVPARTBLMEntity=(PARTBLMEntity)objEntityContainer[0];
					if (objVPARTBLMEntity.Verified)
					{
						 _Entity.ITEM_NO=objVPARTBLMEntity.ITEM_NO;

					}else{
						_Entity.Exceptions.Add(new LogisticException("ITEM_NO","DataNotFd",_Entity.ITEM_NO));
					}
			}
			}
//PARTBLM

				// Relation PARTBLM
			if (!Util.IsNullOrEmpty(_Entity.ITEM_NO))
			{
			objRetrieveEntity=new CriteriaRetrieve(typeof(PARTBLMEntity));//物料资料主表
			objRetrieveEntity.Top=1;

			objCondition=objRetrieveEntity.NewCondition();
			objCondition.Equals("ITEM_NO",_Entity.ITEM_NO);
				_DataPermission.TABLE_NAME="PARTBLM";
				_DataPermission.AccessCondition(objCondition);
			objEntityContainer=this.Trans.RetrieveEntitys(objRetrieveEntity);

			if (objEntityContainer.Count==0)
			{
				_Entity.Exceptions.Add(new LogisticException("ITEM_NO","DataNotFd",_Entity.ITEM_NO));
			}else{

					PARTBLMEntity objVPARTBLMEntity=(PARTBLMEntity)objEntityContainer[0];
					if (objVPARTBLMEntity.Verified)
					{
						 _Entity.ITEM_NO=objVPARTBLMEntity.ITEM_NO;

					}else{
						_Entity.Exceptions.Add(new LogisticException("ITEM_NO","DataNotFd",_Entity.ITEM_NO));
					}
			}
			}
//PARTBLM

				// Relation UOMTBLM
			if (!Util.IsNullOrEmpty(_Entity.UOM_CODE))
			{
			objRetrieveEntity=new CriteriaRetrieve(typeof(UOMTBLMEntity));//单位资料
			objRetrieveEntity.Top=1;

			objCondition=objRetrieveEntity.NewCondition();
			objCondition.Equals("UOM_CODE",_Entity.UOM_CODE);
				_DataPermission.TABLE_NAME="UOMTBLM";
				_DataPermission.AccessCondition(objCondition);
			objEntityContainer=this.Trans.RetrieveEntitys(objRetrieveEntity);

			if (objEntityContainer.Count==0)
			{
				_Entity.Exceptions.Add(new LogisticException("UOM_CODE","DataNotFd",_Entity.UOM_CODE));
			}else{

					UOMTBLMEntity objVUOMTBLMEntity=(UOMTBLMEntity)objEntityContainer[0];
					if (objVUOMTBLMEntity.Verified)
					{
						 _Entity.UOM_CODE=objVUOMTBLMEntity.UOM_CODE;

					}else{
						_Entity.Exceptions.Add(new LogisticException("UOM_CODE","DataNotFd",_Entity.UOM_CODE));
					}
			}
			}
//UOMTBLM

				// Relation WHLOCTM
			if (!Util.IsNullOrEmpty(_Entity.TRANS_UDFX1))
			{
			objRetrieveEntity=new CriteriaRetrieve(typeof(WHLOCTMEntity));//仓位资料
			objRetrieveEntity.Top=1;

			objCondition=objRetrieveEntity.NewCondition();
			objCondition.Equals("LOC_CODE",_Entity.TRANS_UDFX1);
			objCondition.Equals("WH_CODE",_Entity.WH_CODE);
				_DataPermission.TABLE_NAME="WHLOCTM";
				_DataPermission.AccessCondition(objCondition);
			objEntityContainer=this.Trans.RetrieveEntitys(objRetrieveEntity);

			if (objEntityContainer.Count==0)
			{
				_Entity.Exceptions.Add(new LogisticException("TRANS_UDFX1","DataNotFd",_Entity.TRANS_UDFX1));
			}else{

					WHLOCTMEntity objVWHLOCTMEntity=(WHLOCTMEntity)objEntityContainer[0];
					if (objVWHLOCTMEntity.Verified)
					{
						 _Entity.TRANS_UDFX1=objVWHLOCTMEntity.LOC_CODE;
						 _Entity.WH_CODE=objVWHLOCTMEntity.WH_CODE;

					}else{
						_Entity.Exceptions.Add(new LogisticException("TRANS_UDFX1","DataNotFd",_Entity.TRANS_UDFX1));
					}
			}
			}
//WHLOCTM

				// Relation WHLOCTM
			if (!Util.IsNullOrEmpty(_Entity.TRANS_UDFN1))
			{
			objRetrieveEntity=new CriteriaRetrieve(typeof(WHLOCTMEntity));//仓位资料
			objRetrieveEntity.Top=1;

			objCondition=objRetrieveEntity.NewCondition();
			objCondition.Equals("LOC_CODE",_Entity.TRANS_UDFN1);
			objCondition.Equals("WH_CODE",_Entity.WH_REFX);
				_DataPermission.TABLE_NAME="WHLOCTM";
				_DataPermission.AccessCondition(objCondition);
			objEntityContainer=this.Trans.RetrieveEntitys(objRetrieveEntity);

			if (objEntityContainer.Count==0)
			{
				_Entity.Exceptions.Add(new LogisticException("TRANS_UDFN1","DataNotFd",_Entity.TRANS_UDFN1));
			}else{

					WHLOCTMEntity objVWHLOCTMEntity=(WHLOCTMEntity)objEntityContainer[0];
					if (objVWHLOCTMEntity.Verified)
					{
						 _Entity.TRANS_UDFN1=objVWHLOCTMEntity.LOC_CODE;
						 _Entity.WH_REFX=objVWHLOCTMEntity.WH_CODE;

					}else{
						_Entity.Exceptions.Add(new LogisticException("TRANS_UDFN1","DataNotFd",_Entity.TRANS_UDFN1));
					}
			}
			}
//WHLOCTM

				// Relation COLORTM
			if (!Util.IsNullOrEmpty(_Entity.TRANS_UDFX3))
			{
			objRetrieveEntity=new CriteriaRetrieve(typeof(COLORTMEntity));//颜色码资料
			objRetrieveEntity.Top=1;

			objCondition=objRetrieveEntity.NewCondition();
			objCondition.Equals("COLOR_CODE",_Entity.TRANS_UDFX3);
				_DataPermission.TABLE_NAME="COLORTM";
				_DataPermission.AccessCondition(objCondition);
			objEntityContainer=this.Trans.RetrieveEntitys(objRetrieveEntity);

			if (objEntityContainer.Count==0)
			{
				_Entity.Exceptions.Add(new LogisticException("TRANS_UDFX3","DataNotFd",_Entity.TRANS_UDFX3));
			}else{

					COLORTMEntity objVCOLORTMEntity=(COLORTMEntity)objEntityContainer[0];
					if (objVCOLORTMEntity.Verified)
					{
						 _Entity.TRANS_UDFX3=objVCOLORTMEntity.COLOR_CODE;

					}else{
						_Entity.Exceptions.Add(new LogisticException("TRANS_UDFX3","DataNotFd",_Entity.TRANS_UDFX3));
					}
			}
			}
//COLORTM

				// Relation SIZECDM
			if (!Util.IsNullOrEmpty(_Entity.TRANS_UDFX4))
			{
			objRetrieveEntity=new CriteriaRetrieve(typeof(SIZECDMEntity));//尺寸资料
			objRetrieveEntity.Top=1;

			objCondition=objRetrieveEntity.NewCondition();
			objCondition.Equals("SIZE_CODE",_Entity.TRANS_UDFX4);
				_DataPermission.TABLE_NAME="SIZECDM";
				_DataPermission.AccessCondition(objCondition);
			objEntityContainer=this.Trans.RetrieveEntitys(objRetrieveEntity);

			if (objEntityContainer.Count==0)
			{
				_Entity.Exceptions.Add(new LogisticException("TRANS_UDFX4","DataNotFd",_Entity.TRANS_UDFX4));
			}else{

					SIZECDMEntity objVSIZECDMEntity=(SIZECDMEntity)objEntityContainer[0];
					if (objVSIZECDMEntity.Verified)
					{
						 _Entity.TRANS_UDFX4=objVSIZECDMEntity.SIZE_CODE;

					}else{
						_Entity.Exceptions.Add(new LogisticException("TRANS_UDFX4","DataNotFd",_Entity.TRANS_UDFX4));
					}
			}
			}
//SIZECDM

				return _Entity;
		}

		public List<UID08025BE> Verify(List<UID08025BE> _Entitys)
		{
			List<UID08025BE> _New_Entitys=new List<UID08025BE>();

			foreach (UID08025BE _Entity in _Entitys) 
			{
				_New_Entitys.Add(Verify(_Entity));
			}
			return _New_Entitys;
		}

		public UID08025BE Default(UID08025BE _Entity)
		{

						_Entity.TM_DT=objDefault.getDefault("TM_DT",_Entity.TM_DT);
						_Entity.SERIAL_NO=objDefault.getDefault("SERIAL_NO",_Entity.SERIAL_NO);
						_Entity.TRANS_CODE=objDefault.getDefault("TRANS_CODE",_Entity.TRANS_CODE);
						_Entity.TRANS_DATE=objDefault.getDefault("TRANS_DATE",_Entity.TRANS_DATE);
						_Entity.ITEM_NO=objDefault.getDefault("ITEM_NO",_Entity.ITEM_NO);
						_Entity.ITEM_NAME01=objDefault.getDefault("ITEM_NAME01",_Entity.ITEM_NAME01);
						_Entity.UOM_CODE=objDefault.getDefault("UOM_CODE",_Entity.UOM_CODE);
						_Entity.ITEM_NAME02=objDefault.getDefault("ITEM_NAME02",_Entity.ITEM_NAME02);
						_Entity.WH_CODE=objDefault.getDefault("WH_CODE",_Entity.WH_CODE);
						_Entity.TRANS_UDFX1=objDefault.getDefault("TRANS_UDFX1",_Entity.TRANS_UDFX1);
						_Entity.STK_QTY=objDefault.getDefault("STK_QTY",_Entity.STK_QTY);
						_Entity.WH_REFX=objDefault.getDefault("WH_REFX",_Entity.WH_REFX);
						_Entity.TRANS_UDFN1=objDefault.getDefault("TRANS_UDFN1",_Entity.TRANS_UDFN1);
						_Entity.STK_QTY_TO=objDefault.getDefault("STK_QTY_TO",_Entity.STK_QTY_TO);
						_Entity.TRANS_QTY=objDefault.getDefault("TRANS_QTY",_Entity.TRANS_QTY);
						_Entity.TRANS_UDFX3=objDefault.getDefault("TRANS_UDFX3",_Entity.TRANS_UDFX3);
						_Entity.TRANS_UDFX4=objDefault.getDefault("TRANS_UDFX4",_Entity.TRANS_UDFX4);
						_Entity.REFX_NO=objDefault.getDefault("REFX_NO",_Entity.REFX_NO);
						_Entity.TRANS_RMK=objDefault.getDefault("TRANS_RMK",_Entity.TRANS_RMK);

					// WriteDefault TMRHDTM
ZZTrace.Debug(ZFILE_NAME,"_Entity.TM_NO="+_Entity.TM_NO);
			if (!Util.IsNullOrEmpty(_Entity.TM_NO))
			{
			objRetrieveEntity=new CriteriaRetrieve(typeof(TMRHDTMEntity));//仓库转移单主节
			objRetrieveEntity.Top=1;

			objCondition=objRetrieveEntity.NewCondition();
			objCondition.Equals("TM_NO",_Entity.TM_NO);
				_DataPermission.TABLE_NAME="TMRHDTM";
				_DataPermission.AccessCondition(objCondition);
			objEntityContainer=this.Trans.RetrieveEntitys(objRetrieveEntity);

ZZTrace.Debug(ZFILE_NAME,"TMRHDTM"+objEntityContainer.Count);
			if (objEntityContainer.Count>0)
			{

					TMRHDTMEntity objDTMRHDTMEntity=(TMRHDTMEntity)objEntityContainer[0];
					if (objDTMRHDTMEntity.Verified)
					{
						 _Entity.TM_NO=objDTMRHDTMEntity.TM_NO;
						 _Entity.REFX_NO=objDTMRHDTMEntity.REFX_NO;
						 _Entity.TRANS_CODE=objDTMRHDTMEntity.TRANS_CODE;
						 _Entity.TRANS_DATE=objDTMRHDTMEntity.TRANS_DATE;
						 _Entity.WH_CODE=objDTMRHDTMEntity.WH_CODE;
						 _Entity.WH_REFX=objDTMRHDTMEntity.WH_REFX;

					}else{
					}
			}else{
			}
			}

					// WriteDefault PARTBLM
ZZTrace.Debug(ZFILE_NAME,"_Entity.ITEM_NO="+_Entity.ITEM_NO);
			if (!Util.IsNullOrEmpty(_Entity.ITEM_NO))
			{
			objRetrieveEntity=new CriteriaRetrieve(typeof(PARTBLMEntity));//物料资料主表
			objRetrieveEntity.Top=1;

			objCondition=objRetrieveEntity.NewCondition();
			objCondition.Equals("ITEM_NO",_Entity.ITEM_NO);
				_DataPermission.TABLE_NAME="PARTBLM";
				_DataPermission.AccessCondition(objCondition);
			objEntityContainer=this.Trans.RetrieveEntitys(objRetrieveEntity);

ZZTrace.Debug(ZFILE_NAME,"PARTBLM"+objEntityContainer.Count);
			if (objEntityContainer.Count>0)
			{

					PARTBLMEntity objDPARTBLMEntity=(PARTBLMEntity)objEntityContainer[0];
					if (objDPARTBLMEntity.Verified)
					{
						 _Entity.ITEM_NO=objDPARTBLMEntity.ITEM_NO;
						 _Entity.ITEM_NAME01=objDPARTBLMEntity.ITEM_NAME01;
						 _Entity.ITEM_NAME02=objDPARTBLMEntity.ITEM_NAME02;
						 _Entity.UOM_CODE=objDPARTBLMEntity.UOM_CODE;

					}else{
					}
			}else{
			}
			}

				return _Entity;
		}

		public List<UID08025BE> Default(List<UID08025BE> _Entitys)
		{
			List<UID08025BE> _New_Entitys=new List<UID08025BE>();
			foreach (UID08025BE _Entity in _Entitys) 
			{
				_New_Entitys.Add(Default(_Entity));
			}
			return _New_Entitys;
		}

		public UID08025BE Search(VContexts _VContexts,UID08025BE _Entity)
		{

			if (_DocsPermission.AccessRight("UID08025B", this.ZZLOGON_ID, "ACCESS")==false)
			{
				_Entity.Exceptions.Add(new LogisticException("UID08025B","NotAccessRight", this.ZZLOGON_ID));
				return _Entity;
			}

			ZZSQLStatement  _SQLStatement = new ZZSQLStatement();

			_SQLStatement.Trans         = this.Trans;
			_SQLStatement.UID_CODE      = "UID08025B";
			_SQLStatement.ZZLOGON_SSD   = this.ZZLOGON_SSD;
			_SQLStatement.ZZLOGON_LANG  = this.ZZLOGON_LANG;
			_SQLStatement.DbName        = this.DbName;
			_SQLStatement.Process("QID08025B");

			ZZQLite oZZQLite = _SQLStatement.oZZQLite;

			if (_VContexts.getValue("T1")!="" && _VContexts.getValue("V1")!="")
			{
				oZZQLite.AddXWhereClause("", _VContexts.getValue("T1"), _VContexts.getValue("V1"));
			}
			if (_VContexts.getValue("T2")!="" && _VContexts.getValue("V2")!="")
			{
				oZZQLite.AddXWhereClause("", _VContexts.getValue("T2"), _VContexts.getValue("V2"));
			}
			if (_VContexts.getValue("T3")!="" && _VContexts.getValue("V3")!="")
			{
				oZZQLite.AddXWhereClause("", _VContexts.getValue("T3"), _VContexts.getValue("V3"));
			}

			if (!Util.IsNullOrEmpty(_VContexts.getValue("lookup")))
			{
				oZZQLite.AddXWhereClause("A", "", _VContexts.getValue("lookup"));
			}

						_VContexts.setValue("TT1","TMRDTLM.TM_NO");
						_VContexts.setValue("VV1",_Entity.TM_NO);
						oZZQLite.AddWhereClause("TMRDTLM", "TM_NO", _Entity.TM_NO);

			oZZQLite.Condition=_VContexts.getValue("Condition");
			oZZQLite.Make();

			int _AbsolutePage = _VContexts.getInteger("AbsolutePage");
			int _PageSize     = _VContexts.getInteger("ZZPageSize");
			int _Restrict     = _VContexts.getInteger("Restrict");
			int _TotalPages   = 0;

			_Setting.Trans      = this.Trans;

			if (_Restrict == 0)
			{
				_Restrict=30;
			}

			if (_PageSize <= 0)
			{
				_PageSize=_Setting.getInteger("ZZPageSize","20");
			}

				QueryRows RsTMRDTLM   = new QueryRows(this.Trans);
			RsTMRDTLM.CommandText = oZZQLite.SQLStatement;
			RsTMRDTLM.Top         = _Restrict;
			RsTMRDTLM.Skip        = (_AbsolutePage-1)*_PageSize;
			RsTMRDTLM.Limit       = _PageSize;
			RsTMRDTLM.CountAll    = true;
			RsTMRDTLM.Open();

			if (_PageSize <= 0)
			{
				_TotalPages   = RsTMRDTLM.RecordCount;
				_PageSize = RsTMRDTLM.RecordCount;
			}
			else
			{
				_TotalPages= RsTMRDTLM.RecordCount / _PageSize;
			}
			if (RsTMRDTLM.RecordCount > (RsTMRDTLM.RecordCount / _PageSize) * _PageSize)
			{
				_TotalPages = _TotalPages+ 1;
			}

			if (_AbsolutePage <= 0)
			{
				_AbsolutePage = 1;
			}

			if (_AbsolutePage > _TotalPages)
			{
				_AbsolutePage = _TotalPages;
			}

			Wxf _Wxf  = new Wxf();

			_Wxf.XDeclareStart();
			foreach(AttributeMapping _AttributeMapping in oZZQLite.AttributeMappings)
			{
				if (_AttributeMapping.STATUS_CODE != "HIDDEN")
				{
					_Wxf.XDeclare(_AttributeMapping);
				}
			}
			_Wxf.XDeclareFinal();

			_Wxf.Variable("ZZPageSize",_PageSize);
			_Wxf.Variable("ZZPages",_TotalPages);
			_Wxf.Variable("USQL_CODE","QID08025B");

			while (!RsTMRDTLM.EOF)
			{
				string cPickUpData   = "";
				object cValue;

				_Wxf.AddNew();
				int i=0;
				foreach(AttributeMapping _AttributeMapping in oZZQLite.AttributeMappings)
				{

					cValue = RsTMRDTLM[i];

					if (_AttributeMapping.STATUS_CODE != "HIDDEN")
					{
						_Wxf[_AttributeMapping.Name] = cValue;
					}

					if (_AttributeMapping.PrimaryKey)
					{
						if (cPickUpData != "")
						{
							cPickUpData = cPickUpData + "|";
						}
						cPickUpData = cPickUpData + ZZGeneral.Base64Encoder(_AttributeMapping.ColumnName + "=" + cValue);
					}
					i++;
				}

				_Wxf.PK_DATA   = cPickUpData;
				_Wxf.Update();

				RsTMRDTLM.MoveNext();
			}
			RsTMRDTLM.Close();

			_Entity.Wxf=_Wxf;

			return _Entity;
		}

		public UID08025BE Retrieves(VContexts _VContexts,UID08025BE _Entity)
		{
			if (_DocsPermission.AccessRight("UID08025B", this.ZZLOGON_ID, "ACCESS")==false)
			{
				_Entity.Exceptions.Add(new LogisticException("UID08025B","NotAccessRight",this.ZZLOGON_ID));
				return _Entity;
			}

			List<UID08025BE> _New_Entitys=new List<UID08025BE>();

				CriteriaRetrieve objRetrieveTMRDTLMEntity=new CriteriaRetrieve(typeof(TMRDTLMEntity));

			objRetrieveTMRDTLMEntity.Top=1;
			objCondition=objRetrieveTMRDTLMEntity.NewCondition();

			bool ZZOrderByAsc=_Setting.getBoolean("ZZOrderByAsc","YES");
			switch (_VContexts.getValue("UDEF_CODE"))
			{
				case "MF":
					{
						objRetrieveTMRDTLMEntity.OrderBy("TM_DT",ZZOrderByAsc);
						break;
					}
				case "ML":
					{
						objRetrieveTMRDTLMEntity.OrderBy("TM_DT",!ZZOrderByAsc);
						break;
					}
				case "MN":
					{
						if (ZZOrderByAsc)
						{
							objCondition.GreaterThan("TM_DT",_Entity.TM_DT);
						}else{
							objCondition.LessThan("TM_DT",_Entity.TM_DT);
						}
						objRetrieveTMRDTLMEntity.OrderBy("TM_DT",ZZOrderByAsc);
						break;
					}
				case "MP":
					{
						if (ZZOrderByAsc)
						{
							objCondition.LessThan("TM_DT",_Entity.TM_DT);
						}else{
							objCondition.GreaterThan("TM_DT",_Entity.TM_DT);
						}
						objRetrieveTMRDTLMEntity.OrderBy("TM_DT",!ZZOrderByAsc);
						break;
					}
				case "CANCEL":
					{
						objRetrieveTMRDTLMEntity.OrderBy("TM_DT",ZZOrderByAsc);
						_Entity.DATA_STATUS_CODE="Verified";
						break;
					}
				case "LOOKUP":
					{
						objRetrieveTMRDTLMEntity.OrderBy("TM_DT",ZZOrderByAsc);
						break;
					}

				case "ACTIVETAB":
					{
								if (_Entity.TM_DT != "")
								{
									objCondition.Equals("TM_DT", _Entity.TM_DT);
								}

						objRetrieveTMRDTLMEntity.OrderBy("TM_DT",ZZOrderByAsc);
						break;
					}

				case "READ":
					{
								objCondition.Equals("TM_DT", _Entity.TM_DT);
						break;
					}					
				default:
					{
								if (_Entity.TM_DT != "")
								{
									objCondition.Equals("TM_DT", _Entity.TM_DT);
								}
						objRetrieveTMRDTLMEntity.OrderBy("TM_DT",ZZOrderByAsc);

						break;
					}
			}

			//filter by quick look
			string _LOOUP_COLUMN_NAME=";TMRDTLM.TM_NO;TMRDTLM.TM_DT;TMRDTLM.ITEM_NO;TMRDTLM.UOM_CODE;TMRDTLM.TRANS_UDFX1;TMRDTLM.TRANS_UDFN1;TMRDTLM.TRANS_UDFX3;TMRDTLM.TRANS_UDFX4;TMRDTLM.REFX_NO;TMRDTLM.TRANS_RMK";
			string lookup=_VContexts.getValue("lookup");
			_LOOUP_COLUMN_NAME=_LOOUP_COLUMN_NAME+";";
			if (lookup!="")
			{
				Condition _Condition2=objCondition.NewCondition(" AND ");
				foreach (string s in _LOOUP_COLUMN_NAME.Split(new char[] { ';' }))
				{
					if (!string.IsNullOrEmpty(s))
					{
						Condition OrCondition=_Condition2.NewCondition();
						OrCondition.Expression(s,lookup);
					}
				}
			}

			//filter by filters

				//filter by AccessConditions
				_DataPermission.AccessCondition(objCondition);

						objCondition.Equals("TM_NO", _Entity.TM_NO);

			TMRDTLMEntity objTMRDTLMs=(TMRDTLMEntity)this.Trans.RetrieveEntity(objRetrieveTMRDTLMEntity);

			ZZTrace.Debug(ZFILE_NAME,"SELECT="+objRetrieveTMRDTLMEntity.SELECTClause);

			if (objTMRDTLMs==null && _VContexts.getValue("UDEF_CODE")=="MN")
			{
				_Entity.Exceptions.Add(new LogisticException("TM_DT","DataEOF"));
				return _Entity;
			}else if (objTMRDTLMs==null && _VContexts.getValue("UDEF_CODE")=="MP")
			{
				_Entity.Exceptions.Add(new LogisticException("TM_DT","DataBOF"));
				return _Entity;
			}else if (objTMRDTLMs==null && (_VContexts.getValue("UDEF_CODE")=="MF" || _VContexts.getValue("UDEF_CODE")=="ML") )
			{
				_Entity.Exceptions.Add(new LogisticException("TM_DT","DataBlank"));
				return _Entity;
			}else if (objTMRDTLMs==null && _VContexts.getValue("UDEF_CODE")=="LOOKUP")
			{
				/*
				 *if (this.COLUMN_REFX.IndexOf(";")>=0)
				 *{
				 *}else{
				 *    string _T_COLUMN_REFX=this.COLUMN_REFX;
				 *    if (_T_COLUMN_REFX.IndexOf('.') > 0)
				 *    {
				 *        string[] s = _T_COLUMN_REFX.Split(new char[] { '.' });
				 *        _T_COLUMN_REFX=s[1];
				 *    }
				 *    _Entity.Exceptions.Add(new LogisticException(_T_COLUMN_REFX,"DataNotFd","DataBlank"));
				 *    return _Entity;
				 *}
				 */
			}else if (objTMRDTLMs==null && _VContexts.getValue("UDEF_CODE")=="ACTIVETAB")
			{
				//throw new LogisticException("TM_DT","Activetab","");
				//this.Default(_Entity);
			}else if (objTMRDTLMs==null)
			{
				//this.Default(_Entity);
			}else{
				TMRDTLMEntity objTMRDTLMEntity = objTMRDTLMs;
					ZZTrace.MUKI_DEBUG_LOG=true;
						_Entity.TM_NO=objTMRDTLMEntity.TM_NO;
						_Entity.TM_DT=objTMRDTLMEntity.TM_DT;
						_Entity.SERIAL_NO=objTMRDTLMEntity.SERIAL_NO;
						_Entity.ITEM_NO=objTMRDTLMEntity.ITEM_NO;
						_Entity.UOM_CODE=objTMRDTLMEntity.UOM_CODE;
						_Entity.TRANS_UDFX1=objTMRDTLMEntity.TRANS_UDFX1;
						_Entity.TRANS_UDFN1=objTMRDTLMEntity.TRANS_UDFN1;
						_Entity.TRANS_QTY=objTMRDTLMEntity.TRANS_QTY;
						_Entity.TRANS_UDFX3=objTMRDTLMEntity.TRANS_UDFX3;
						_Entity.TRANS_UDFX4=objTMRDTLMEntity.TRANS_UDFX4;
						_Entity.REFX_NO=objTMRDTLMEntity.REFX_NO;
						_Entity.TRANS_RMK=objTMRDTLMEntity.TRANS_RMK;

				_Entity.UZADD_DATE     =_Convert.ToDateTimeString(objTMRDTLMEntity.ZADD_DATE);
_Entity.UZADD_USER     =objTMRDTLMEntity.ZADD_USER;
_Entity.UZCHG_DATE     =_Convert.ToDateTimeString(objTMRDTLMEntity.ZCHG_DATE);
_Entity.UZCHG_USER     =objTMRDTLMEntity.ZCHG_USER;
_Entity.USECURITY_CODE1=objTMRDTLMEntity.ZSECURITY_CODE1;
_Entity.USECURITY_CODE2=objTMRDTLMEntity.ZSECURITY_CODE2;
_Entity.USECURITY_CODE3=objTMRDTLMEntity.ZSECURITY_CODE3;
_Entity.USECURITY_CODE4=objTMRDTLMEntity.ZSECURITY_CODE4;
_Entity.USECURITY_CODE5=objTMRDTLMEntity.ZSECURITY_CODE5;
_Entity.USECURITY_CODE6=objTMRDTLMEntity.ZSECURITY_CODE6;

					// WriteDefault TMRHDTM
ZZTrace.Debug(ZFILE_NAME,"_Entity.TM_NO="+_Entity.TM_NO);
			if (!Util.IsNullOrEmpty(_Entity.TM_NO))
			{
			objRetrieveEntity=new CriteriaRetrieve(typeof(TMRHDTMEntity));//仓库转移单主节
			objRetrieveEntity.Top=1;

			objCondition=objRetrieveEntity.NewCondition();
			objCondition.Equals("TM_NO",_Entity.TM_NO);
				_DataPermission.TABLE_NAME="TMRHDTM";
				_DataPermission.AccessCondition(objCondition);
			objEntityContainer=this.Trans.RetrieveEntitys(objRetrieveEntity);

ZZTrace.Debug(ZFILE_NAME,"TMRHDTM"+objEntityContainer.Count);
			if (objEntityContainer.Count>0)
			{

					TMRHDTMEntity objDTMRHDTMEntity=(TMRHDTMEntity)objEntityContainer[0];
					if (objDTMRHDTMEntity.Verified)
					{
						 _Entity.TM_NO=objDTMRHDTMEntity.TM_NO;
						 _Entity.REFX_NO=objDTMRHDTMEntity.REFX_NO;
						 _Entity.TRANS_CODE=objDTMRHDTMEntity.TRANS_CODE;
						 _Entity.TRANS_DATE=objDTMRHDTMEntity.TRANS_DATE;
						 _Entity.WH_CODE=objDTMRHDTMEntity.WH_CODE;
						 _Entity.WH_REFX=objDTMRHDTMEntity.WH_REFX;

					}else{
					}
			}else{
			}
			}

					// WriteDefault PARTBLM
ZZTrace.Debug(ZFILE_NAME,"_Entity.ITEM_NO="+_Entity.ITEM_NO);
			if (!Util.IsNullOrEmpty(_Entity.ITEM_NO))
			{
			objRetrieveEntity=new CriteriaRetrieve(typeof(PARTBLMEntity));//物料资料主表
			objRetrieveEntity.Top=1;

			objCondition=objRetrieveEntity.NewCondition();
			objCondition.Equals("ITEM_NO",_Entity.ITEM_NO);
				_DataPermission.TABLE_NAME="PARTBLM";
				_DataPermission.AccessCondition(objCondition);
			objEntityContainer=this.Trans.RetrieveEntitys(objRetrieveEntity);

ZZTrace.Debug(ZFILE_NAME,"PARTBLM"+objEntityContainer.Count);
			if (objEntityContainer.Count>0)
			{

					PARTBLMEntity objDPARTBLMEntity=(PARTBLMEntity)objEntityContainer[0];
					if (objDPARTBLMEntity.Verified)
					{
						 _Entity.ITEM_NO=objDPARTBLMEntity.ITEM_NO;
						 _Entity.ITEM_NAME01=objDPARTBLMEntity.ITEM_NAME01;
						 _Entity.ITEM_NAME02=objDPARTBLMEntity.ITEM_NAME02;
						 _Entity.UOM_CODE=objDPARTBLMEntity.UOM_CODE;

					}else{
					}
			}else{
			}
			}

					// WriteDefault STKRTBM
ZZTrace.Debug(ZFILE_NAME,"_Entity.TRANS_UDFX4="+_Entity.TRANS_UDFX4);
			if (!Util.IsNullOrEmpty(_Entity.TRANS_UDFX4))
			{
			objRetrieveEntity=new CriteriaRetrieve(typeof(STKRTBMEntity));//当前库存
			objRetrieveEntity.Top=1;

			objCondition=objRetrieveEntity.NewCondition();
			objCondition.Equals("ITEM_NO",_Entity.ITEM_NO);
			objCondition.Equals("TRANS_UDFX1",_Entity.TRANS_UDFX1);
			objCondition.Equals("TRANS_UDFX3",_Entity.TRANS_UDFX3);
			objCondition.Equals("TRANS_UDFX4",_Entity.TRANS_UDFX4);
			objCondition.Equals("WH_CODE",_Entity.WH_CODE);
				_DataPermission.TABLE_NAME="STKRTBM";
				_DataPermission.AccessCondition(objCondition);
			objEntityContainer=this.Trans.RetrieveEntitys(objRetrieveEntity);

ZZTrace.Debug(ZFILE_NAME,"STKRTBM"+objEntityContainer.Count);
			if (objEntityContainer.Count>0)
			{

					STKRTBMEntity objDSTKRTBMEntity=(STKRTBMEntity)objEntityContainer[0];
					if (objDSTKRTBMEntity.Verified)
					{
						 _Entity.ITEM_NO=objDSTKRTBMEntity.ITEM_NO;
						 _Entity.TRANS_UDFX1=objDSTKRTBMEntity.TRANS_UDFX1;
						 _Entity.TRANS_UDFX3=objDSTKRTBMEntity.TRANS_UDFX3;
						 _Entity.TRANS_UDFX4=objDSTKRTBMEntity.TRANS_UDFX4;
						 _Entity.WH_CODE=objDSTKRTBMEntity.WH_CODE;
						 _Entity.STK_QTY=objDSTKRTBMEntity.STK_QTY;

					}else{
					}
			}else{
			}
			}

					_Entity.DATA_STATUS_CODE="Verified";
			}
				return _Entity;
		}

		public  UID08025BE AddNew(UID08025BE _Entity)
		{

			ZZTrace.Debug(ZFILE_NAME,"ZZLOGON_ID="+this.ZZLOGON_ID);

			if (_DocsPermission.AccessRight("UID08025B", this.ZZLOGON_ID, "ADDNEW")==false)
			{
				_Entity.Exceptions.Add(new LogisticException("UID08025B","NotAddNewRight",this.ZZLOGON_ID));
				return _Entity;
			}

			_Entity.ATVT_CODE="ADDNEW";

					if (_Entity.ATVT_CODE!="ADDNEW")
					{

						CriteriaRetrieve objValidateEntity=new CriteriaRetrieve(typeof(TMRHDTMEntity));
						objCondition=objValidateEntity.NewCondition();
						objCondition.Equals("TM_NO",_Entity.TM_NO);
			
						EntityObject objValidateObject=this.Trans.RetrieveEntity(objValidateEntity);

						if (objValidateObject!=null)
						{
							TMRHDTMEntity objTMRHDTMEntity=(TMRHDTMEntity)objValidateObject;
							if (objTMRHDTMEntity.ODTP_STATUS=="C")
							{
		        		throw new LogisticException("TM_NO","Posted",_Entity.TM_NO);
							}
						}else{
		        		throw new LogisticException("TM_NO","DataNotFd",_Entity.TM_NO);
						}
					}

				_Entity=this.Verify(_Entity);
			if (_Entity.Exceptions.Count>0)
			{
				return _Entity;
			}
			TMRDTLMEntity objAddNewEntity=new TMRDTLMEntity();

			ZZHDKeyLib objZZHDKeyLib=new ZZHDKeyLib();
			objZZHDKeyLib.Trans=this.Trans;
							objZZHDKeyLib.LNK_COLUMN("TM_NO",_Entity.TM_NO);
							objZZHDKeyLib.LNK_COLUMN_VALUE=_Entity.TM_NO;

				objZZHDKeyLib.PREFIX_CODE="UID08025B";
				objZZHDKeyLib.getSerial("TMRDTLM");
				int XSERIAL_NO=objZZHDKeyLib.PREFIX_CN;

				_Entity.TM_DT=objZZHDKeyLib.DT_NO;

				ZZTrace.Debug(ZFILE_NAME,_Entity.TM_DT);
				ZZTrace.Debug(ZFILE_NAME,XSERIAL_NO);

					objAddNewEntity.TM_DT=_Entity.TM_DT;

			this.Trans.RetrieveEntity(objAddNewEntity);

			if (objAddNewEntity.Verified)
			{
				_Entity.Exceptions.Add(new LogisticException("TM_DT","DataExist",_Entity.TM_DT));
				return _Entity;
			}else{

				objAddNewEntity.ZADD_DATE = DateTime.Now;
				objAddNewEntity.ZADD_USER = this.ZZLOGON_ID;

				_DataPermission.TABLE_NAME="TMRDTLM";
				_DataPermission.DataAccessRight();
				objAddNewEntity.ZSECURITY_CODE1 = _DataPermission.ACCESS_AUTH.getValue("SECURITY_CODE1");
				objAddNewEntity.ZSECURITY_CODE2 = _DataPermission.ACCESS_AUTH.getValue("SECURITY_CODE2");
				objAddNewEntity.ZSECURITY_CODE3 = _DataPermission.ACCESS_AUTH.getValue("SECURITY_CODE3");
				objAddNewEntity.ZSECURITY_CODE4 = _DataPermission.ACCESS_AUTH.getValue("SECURITY_CODE4");
				objAddNewEntity.ZSECURITY_CODE5 = _DataPermission.ACCESS_AUTH.getValue("SECURITY_CODE5");
				objAddNewEntity.ZSECURITY_CODE6 = _DataPermission.ACCESS_AUTH.getValue("SECURITY_CODE6");
				objAddNewEntity.ZSECURITY_RIGHT = _DataPermission.ACCESS_AUTH.getInteger("SECURITY_RIGHT");

				_Entity.UZADD_DATE     =_Convert.ToDateTimeString(objAddNewEntity.ZADD_DATE);
_Entity.UZADD_USER     =objAddNewEntity.ZADD_USER;
_Entity.UZCHG_DATE     =_Convert.ToDateTimeString(objAddNewEntity.ZCHG_DATE);
_Entity.UZCHG_USER     =objAddNewEntity.ZCHG_USER;
_Entity.USECURITY_CODE1=objAddNewEntity.ZSECURITY_CODE1;
_Entity.USECURITY_CODE2=objAddNewEntity.ZSECURITY_CODE2;
_Entity.USECURITY_CODE3=objAddNewEntity.ZSECURITY_CODE3;
_Entity.USECURITY_CODE4=objAddNewEntity.ZSECURITY_CODE4;
_Entity.USECURITY_CODE5=objAddNewEntity.ZSECURITY_CODE5;
_Entity.USECURITY_CODE6=objAddNewEntity.ZSECURITY_CODE6;

							objAddNewEntity.TM_NO=_Entity.TM_NO;
							objAddNewEntity.TM_DT=_Entity.TM_DT;
							objAddNewEntity.ITEM_NO=_Entity.ITEM_NO;
							objAddNewEntity.UOM_CODE=_Entity.UOM_CODE;
							objAddNewEntity.TRANS_UDFX1=_Entity.TRANS_UDFX1;
							objAddNewEntity.TRANS_UDFN1=_Entity.TRANS_UDFN1;
							objAddNewEntity.TRANS_QTY=_Entity.TRANS_QTY;
							objAddNewEntity.TRANS_UDFX3=_Entity.TRANS_UDFX3;
							objAddNewEntity.TRANS_UDFX4=_Entity.TRANS_UDFX4;
							objAddNewEntity.REFX_NO=_Entity.REFX_NO;
							objAddNewEntity.TRANS_RMK=_Entity.TRANS_RMK;
					ZZTrace.Debug(ZFILE_NAME,XSERIAL_NO);

					objAddNewEntity.SERIAL_NO=XSERIAL_NO;
					_Entity.SERIAL_NO=XSERIAL_NO;
			}

				this.Trans.SaveChanges(objAddNewEntity);

				// WriteDefault TMRHDTM
ZZTrace.Debug(ZFILE_NAME,"_Entity.TM_NO="+_Entity.TM_NO);
			if (!Util.IsNullOrEmpty(_Entity.TM_NO))
			{
			objRetrieveEntity=new CriteriaRetrieve(typeof(TMRHDTMEntity));//仓库转移单主节
			objRetrieveEntity.Top=1;

			objCondition=objRetrieveEntity.NewCondition();
			objCondition.Equals("TM_NO",_Entity.TM_NO);
				_DataPermission.TABLE_NAME="TMRHDTM";
				_DataPermission.AccessCondition(objCondition);
			objEntityContainer=this.Trans.RetrieveEntitys(objRetrieveEntity);

ZZTrace.Debug(ZFILE_NAME,"TMRHDTM"+objEntityContainer.Count);
			if (objEntityContainer.Count>0)
			{

					TMRHDTMEntity objDTMRHDTMEntity=(TMRHDTMEntity)objEntityContainer[0];
					if (objDTMRHDTMEntity.Verified)
					{
						 _Entity.TM_NO=objDTMRHDTMEntity.TM_NO;
						 _Entity.REFX_NO=objDTMRHDTMEntity.REFX_NO;
						 _Entity.TRANS_CODE=objDTMRHDTMEntity.TRANS_CODE;
						 _Entity.TRANS_DATE=objDTMRHDTMEntity.TRANS_DATE;
						 _Entity.WH_CODE=objDTMRHDTMEntity.WH_CODE;
						 _Entity.WH_REFX=objDTMRHDTMEntity.WH_REFX;

					}else{
					}
			}else{
			}
			}

				// WriteDefault PARTBLM
ZZTrace.Debug(ZFILE_NAME,"_Entity.ITEM_NO="+_Entity.ITEM_NO);
			if (!Util.IsNullOrEmpty(_Entity.ITEM_NO))
			{
			objRetrieveEntity=new CriteriaRetrieve(typeof(PARTBLMEntity));//物料资料主表
			objRetrieveEntity.Top=1;

			objCondition=objRetrieveEntity.NewCondition();
			objCondition.Equals("ITEM_NO",_Entity.ITEM_NO);
				_DataPermission.TABLE_NAME="PARTBLM";
				_DataPermission.AccessCondition(objCondition);
			objEntityContainer=this.Trans.RetrieveEntitys(objRetrieveEntity);

ZZTrace.Debug(ZFILE_NAME,"PARTBLM"+objEntityContainer.Count);
			if (objEntityContainer.Count>0)
			{

					PARTBLMEntity objDPARTBLMEntity=(PARTBLMEntity)objEntityContainer[0];
					if (objDPARTBLMEntity.Verified)
					{
						 _Entity.ITEM_NO=objDPARTBLMEntity.ITEM_NO;
						 _Entity.ITEM_NAME01=objDPARTBLMEntity.ITEM_NAME01;
						 _Entity.ITEM_NAME02=objDPARTBLMEntity.ITEM_NAME02;
						 _Entity.UOM_CODE=objDPARTBLMEntity.UOM_CODE;

					}else{
					}
			}else{
			}
			}

				// WriteDefault STKRTBM
ZZTrace.Debug(ZFILE_NAME,"_Entity.TRANS_UDFX4="+_Entity.TRANS_UDFX4);
			if (!Util.IsNullOrEmpty(_Entity.TRANS_UDFX4))
			{
			objRetrieveEntity=new CriteriaRetrieve(typeof(STKRTBMEntity));//当前库存
			objRetrieveEntity.Top=1;

			objCondition=objRetrieveEntity.NewCondition();
			objCondition.Equals("ITEM_NO",_Entity.ITEM_NO);
			objCondition.Equals("TRANS_UDFX1",_Entity.TRANS_UDFX1);
			objCondition.Equals("TRANS_UDFX3",_Entity.TRANS_UDFX3);
			objCondition.Equals("TRANS_UDFX4",_Entity.TRANS_UDFX4);
			objCondition.Equals("WH_CODE",_Entity.WH_CODE);
				_DataPermission.TABLE_NAME="STKRTBM";
				_DataPermission.AccessCondition(objCondition);
			objEntityContainer=this.Trans.RetrieveEntitys(objRetrieveEntity);

ZZTrace.Debug(ZFILE_NAME,"STKRTBM"+objEntityContainer.Count);
			if (objEntityContainer.Count>0)
			{

					STKRTBMEntity objDSTKRTBMEntity=(STKRTBMEntity)objEntityContainer[0];
					if (objDSTKRTBMEntity.Verified)
					{
						 _Entity.ITEM_NO=objDSTKRTBMEntity.ITEM_NO;
						 _Entity.TRANS_UDFX1=objDSTKRTBMEntity.TRANS_UDFX1;
						 _Entity.TRANS_UDFX3=objDSTKRTBMEntity.TRANS_UDFX3;
						 _Entity.TRANS_UDFX4=objDSTKRTBMEntity.TRANS_UDFX4;
						 _Entity.WH_CODE=objDSTKRTBMEntity.WH_CODE;
						 _Entity.STK_QTY=objDSTKRTBMEntity.STK_QTY;

					}else{
					}
			}else{
			}
			}

				_Entity.DATA_STATUS_CODE="Verified";
			return _Entity;
		}

		public  UID08025BE Update(UID08025BE _Entity)
		{

			if (_DocsPermission.AccessRight("UID08025B", this.ZZLOGON_ID, "UPDATE")==false)
			{
				_Entity.Exceptions.Add(new LogisticException("UID08025B","NotUpdateRight",this.ZZLOGON_ID));
				return _Entity;
			}
			_Entity.ATVT_CODE="UPDATE";

					if (_Entity.ATVT_CODE!="ADDNEW")
					{

						CriteriaRetrieve objValidateEntity=new CriteriaRetrieve(typeof(TMRHDTMEntity));
						objCondition=objValidateEntity.NewCondition();
						objCondition.Equals("TM_NO",_Entity.TM_NO);
			
						EntityObject objValidateObject=this.Trans.RetrieveEntity(objValidateEntity);

						if (objValidateObject!=null)
						{
							TMRHDTMEntity objTMRHDTMEntity=(TMRHDTMEntity)objValidateObject;
							if (objTMRHDTMEntity.ODTP_STATUS=="C")
							{
		        		throw new LogisticException("TM_NO","Posted",_Entity.TM_NO);
							}
						}else{
		        		throw new LogisticException("TM_NO","DataNotFd",_Entity.TM_NO);
						}
					}

						if (_Entity.TM_DT=="")
						{
							_Entity.Exceptions.Add(new LogisticException("TM_DT","DataMiss",""));
						}

			_Entity=this.Verify(_Entity);
			ZZTrace.Debug(ZFILE_NAME,"_Entity.Exceptions.Count="+_Entity.Exceptions.Count);
			if (_Entity.Exceptions.Count>0)
			{
				return _Entity;
			}

					//ZZTrace.Debug(ZFILE_NAME,"_Entity.TM_NO="+_Entity.TM_NO);
					//ZZTrace.Debug(ZFILE_NAME,"_Entity.TM_DT="+_Entity.TM_DT);
					//ZZTrace.Debug(ZFILE_NAME,"_Entity.ITEM_NO="+_Entity.ITEM_NO);
					//ZZTrace.Debug(ZFILE_NAME,"_Entity.UOM_CODE="+_Entity.UOM_CODE);
					//ZZTrace.Debug(ZFILE_NAME,"_Entity.TRANS_UDFX1="+_Entity.TRANS_UDFX1);
					//ZZTrace.Debug(ZFILE_NAME,"_Entity.TRANS_UDFN1="+_Entity.TRANS_UDFN1);
					//ZZTrace.Debug(ZFILE_NAME,"_Entity.TRANS_QTY="+_Entity.TRANS_QTY);
					//ZZTrace.Debug(ZFILE_NAME,"_Entity.TRANS_UDFX3="+_Entity.TRANS_UDFX3);
					//ZZTrace.Debug(ZFILE_NAME,"_Entity.TRANS_UDFX4="+_Entity.TRANS_UDFX4);
					//ZZTrace.Debug(ZFILE_NAME,"_Entity.REFX_NO="+_Entity.REFX_NO);
					//ZZTrace.Debug(ZFILE_NAME,"_Entity.TRANS_RMK="+_Entity.TRANS_RMK);

			objRetrieveEntity=new CriteriaRetrieve(typeof(TMRDTLMEntity));
			objCondition=objRetrieveEntity.NewCondition();

					objCondition.Equals("TM_DT", _Entity.TM_DT);

			_DataPermission.UpdateCondition(objCondition);

			EntityObject objEntityObject=this.Trans.RetrieveEntity(objRetrieveEntity);

			if (objEntityObject != null)
			{
				TMRDTLMEntity objUpdateEntity=(TMRDTLMEntity)objEntityObject;
				if (objUpdateEntity.Verified)
				{
					objUpdateEntity.ZCHG_DATE=DateTime.Now;
					objUpdateEntity.ZCHG_USER=this.ZZLOGON_ID;

								objUpdateEntity.TM_NO=_Entity.TM_NO;
								objUpdateEntity.TM_DT=_Entity.TM_DT;
								objUpdateEntity.ITEM_NO=_Entity.ITEM_NO;
								objUpdateEntity.UOM_CODE=_Entity.UOM_CODE;
								objUpdateEntity.TRANS_UDFX1=_Entity.TRANS_UDFX1;
								objUpdateEntity.TRANS_UDFN1=_Entity.TRANS_UDFN1;
								objUpdateEntity.TRANS_QTY=_Entity.TRANS_QTY;
								objUpdateEntity.TRANS_UDFX3=_Entity.TRANS_UDFX3;
								objUpdateEntity.TRANS_UDFX4=_Entity.TRANS_UDFX4;
								objUpdateEntity.REFX_NO=_Entity.REFX_NO;
								objUpdateEntity.TRANS_RMK=_Entity.TRANS_RMK;

						this.Trans.SaveChanges(objUpdateEntity);

						// WriteDefault TMRHDTM
ZZTrace.Debug(ZFILE_NAME,"_Entity.TM_NO="+_Entity.TM_NO);
			if (!Util.IsNullOrEmpty(_Entity.TM_NO))
			{
			objRetrieveEntity=new CriteriaRetrieve(typeof(TMRHDTMEntity));//仓库转移单主节
			objRetrieveEntity.Top=1;

			objCondition=objRetrieveEntity.NewCondition();
			objCondition.Equals("TM_NO",_Entity.TM_NO);
				_DataPermission.TABLE_NAME="TMRHDTM";
				_DataPermission.AccessCondition(objCondition);
			objEntityContainer=this.Trans.RetrieveEntitys(objRetrieveEntity);

ZZTrace.Debug(ZFILE_NAME,"TMRHDTM"+objEntityContainer.Count);
			if (objEntityContainer.Count>0)
			{

					TMRHDTMEntity objDTMRHDTMEntity=(TMRHDTMEntity)objEntityContainer[0];
					if (objDTMRHDTMEntity.Verified)
					{
						 _Entity.TM_NO=objDTMRHDTMEntity.TM_NO;
						 _Entity.REFX_NO=objDTMRHDTMEntity.REFX_NO;
						 _Entity.TRANS_CODE=objDTMRHDTMEntity.TRANS_CODE;
						 _Entity.TRANS_DATE=objDTMRHDTMEntity.TRANS_DATE;
						 _Entity.WH_CODE=objDTMRHDTMEntity.WH_CODE;
						 _Entity.WH_REFX=objDTMRHDTMEntity.WH_REFX;

					}else{
					}
			}else{
			}
			}

						// WriteDefault PARTBLM
ZZTrace.Debug(ZFILE_NAME,"_Entity.ITEM_NO="+_Entity.ITEM_NO);
			if (!Util.IsNullOrEmpty(_Entity.ITEM_NO))
			{
			objRetrieveEntity=new CriteriaRetrieve(typeof(PARTBLMEntity));//物料资料主表
			objRetrieveEntity.Top=1;

			objCondition=objRetrieveEntity.NewCondition();
			objCondition.Equals("ITEM_NO",_Entity.ITEM_NO);
				_DataPermission.TABLE_NAME="PARTBLM";
				_DataPermission.AccessCondition(objCondition);
			objEntityContainer=this.Trans.RetrieveEntitys(objRetrieveEntity);

ZZTrace.Debug(ZFILE_NAME,"PARTBLM"+objEntityContainer.Count);
			if (objEntityContainer.Count>0)
			{

					PARTBLMEntity objDPARTBLMEntity=(PARTBLMEntity)objEntityContainer[0];
					if (objDPARTBLMEntity.Verified)
					{
						 _Entity.ITEM_NO=objDPARTBLMEntity.ITEM_NO;
						 _Entity.ITEM_NAME01=objDPARTBLMEntity.ITEM_NAME01;
						 _Entity.ITEM_NAME02=objDPARTBLMEntity.ITEM_NAME02;
						 _Entity.UOM_CODE=objDPARTBLMEntity.UOM_CODE;

					}else{
					}
			}else{
			}
			}

						// WriteDefault STKRTBM
ZZTrace.Debug(ZFILE_NAME,"_Entity.TRANS_UDFX4="+_Entity.TRANS_UDFX4);
			if (!Util.IsNullOrEmpty(_Entity.TRANS_UDFX4))
			{
			objRetrieveEntity=new CriteriaRetrieve(typeof(STKRTBMEntity));//当前库存
			objRetrieveEntity.Top=1;

			objCondition=objRetrieveEntity.NewCondition();
			objCondition.Equals("ITEM_NO",_Entity.ITEM_NO);
			objCondition.Equals("TRANS_UDFX1",_Entity.TRANS_UDFX1);
			objCondition.Equals("TRANS_UDFX3",_Entity.TRANS_UDFX3);
			objCondition.Equals("TRANS_UDFX4",_Entity.TRANS_UDFX4);
			objCondition.Equals("WH_CODE",_Entity.WH_CODE);
				_DataPermission.TABLE_NAME="STKRTBM";
				_DataPermission.AccessCondition(objCondition);
			objEntityContainer=this.Trans.RetrieveEntitys(objRetrieveEntity);

ZZTrace.Debug(ZFILE_NAME,"STKRTBM"+objEntityContainer.Count);
			if (objEntityContainer.Count>0)
			{

					STKRTBMEntity objDSTKRTBMEntity=(STKRTBMEntity)objEntityContainer[0];
					if (objDSTKRTBMEntity.Verified)
					{
						 _Entity.ITEM_NO=objDSTKRTBMEntity.ITEM_NO;
						 _Entity.TRANS_UDFX1=objDSTKRTBMEntity.TRANS_UDFX1;
						 _Entity.TRANS_UDFX3=objDSTKRTBMEntity.TRANS_UDFX3;
						 _Entity.TRANS_UDFX4=objDSTKRTBMEntity.TRANS_UDFX4;
						 _Entity.WH_CODE=objDSTKRTBMEntity.WH_CODE;
						 _Entity.STK_QTY=objDSTKRTBMEntity.STK_QTY;

					}else{
					}
			}else{
			}
			}

						_Entity.UZADD_DATE     =_Convert.ToDateTimeString(objUpdateEntity.ZADD_DATE);
_Entity.UZADD_USER     =objUpdateEntity.ZADD_USER;
_Entity.UZCHG_DATE     =_Convert.ToDateTimeString(objUpdateEntity.ZCHG_DATE);
_Entity.UZCHG_USER     =objUpdateEntity.ZCHG_USER;
_Entity.USECURITY_CODE1=objUpdateEntity.ZSECURITY_CODE1;
_Entity.USECURITY_CODE2=objUpdateEntity.ZSECURITY_CODE2;
_Entity.USECURITY_CODE3=objUpdateEntity.ZSECURITY_CODE3;
_Entity.USECURITY_CODE4=objUpdateEntity.ZSECURITY_CODE4;
_Entity.USECURITY_CODE5=objUpdateEntity.ZSECURITY_CODE5;
_Entity.USECURITY_CODE6=objUpdateEntity.ZSECURITY_CODE6;

					_Entity.DATA_STATUS_CODE="Verified";

				}else{
					_Entity.Exceptions.Add(new LogisticException("TM_DT","DataNotFd"));
				}
			}else{
				_Entity.Exceptions.Add(new LogisticException("TM_DT","DataNotFd"));
			}
			return _Entity;
		}

		public  UID08025BE Delete(UID08025BE _Entity)
		{
			if (_DocsPermission.AccessRight("UID08025B", this.ZZLOGON_ID, "DELETE")==false)
			{
				_Entity.Exceptions.Add(new LogisticException("UID08025B","NotDeleteRight"));
				return _Entity;
			}
			_Entity.ATVT_CODE="DELETE";

					if (_Entity.TM_DT=="")
					{
						_Entity.Exceptions.Add(new LogisticException("TM_DT","DataMiss"));
						return _Entity;
					}

					if (_Entity.ATVT_CODE!="ADDNEW")
					{

						CriteriaRetrieve objValidateEntity=new CriteriaRetrieve(typeof(TMRHDTMEntity));
						objCondition=objValidateEntity.NewCondition();
						objCondition.Equals("TM_NO",_Entity.TM_NO);
			
						EntityObject objValidateObject=this.Trans.RetrieveEntity(objValidateEntity);

						if (objValidateObject!=null)
						{
							TMRHDTMEntity objTMRHDTMEntity=(TMRHDTMEntity)objValidateObject;
							if (objTMRHDTMEntity.ODTP_STATUS=="C")
							{
		        		throw new LogisticException("TM_NO","Posted",_Entity.TM_NO);
							}
						}else{
		        		throw new LogisticException("TM_NO","DataNotFd",_Entity.TM_NO);
						}
					}

				objRetrieveEntity=new CriteriaRetrieve(typeof(TMRDTLMEntity));
			objCondition=objRetrieveEntity.NewCondition();

					objCondition.Equals("TM_DT", _Entity.TM_DT);

			_DataPermission.DeleteCondition(objCondition);

			EntityObject objDeleteEntity=this.Trans.RetrieveEntity(objRetrieveEntity);

			if (objDeleteEntity != null)
			{
				if (objDeleteEntity.Verified)
				{
						this.Trans.DeleteEntity(objDeleteEntity);
						StringBuilder delete_cmd=new StringBuilder(this.ZZLOGON_ID+"UID08025B-DELETED=");
							delete_cmd.Append("TM_DT="+_Entity.TM_DT);

					ZZTrace.Debug("DELETED_LOG",delete_cmd.ToString());

				}else{
					_Entity.Exceptions.Add(new LogisticException("TM_DT","DataNotFd"));
					return _Entity;
				}
			}else{
				_Entity.Exceptions.Add(new LogisticException("TM_DT","DataNotFd"));
			}
			return _Entity;

		}

		public UID08025BE UserDefine(VContexts cMethod,UID08025BE _Entity)
		{

			if (_Entity.TM_NO=="")
			{
					throw new LogisticException("TM_NO","DataMiss","");
			}

			CriteriaRetrieve objRetrieveEntity=new CriteriaRetrieve(typeof(TMRHDTMEntity));
			objRetrieveEntity.Top=1;
			Condition objCondition=objRetrieveEntity.NewCondition();

			objCondition.Equals("TM_NO",_Entity.TM_NO);
			
			List<EntityObject>  objEntityContainer=this.Trans.RetrieveEntitys(objRetrieveEntity);

			if (objEntityContainer==null)
			{
					throw new LogisticException("TM_NO","DataNotFd",_Entity.TM_NO);
			}

			TMRHDTMEntity objTMRHDTMEntity=(TMRHDTMEntity)objEntityContainer[0];

			if (objTMRHDTMEntity.ODTP_STATUS=="C")
			{
					throw new LogisticException("TM_NO","Posted",_Entity.TM_NO);
			}

			objTMRHDTMEntity.ODTP_STATUS="C";

			this.Trans.SaveChanges(objTMRHDTMEntity);

			CriteriaRetrieve objDetailEntity=new CriteriaRetrieve(typeof(TMRDTLMEntity));
			objCondition=objDetailEntity.NewCondition();
			objCondition.Equals("TM_NO",_Entity.TM_NO);

//			ZZTrace.Debug(ZFILE_NAME,objDetailEntity.SqlString);

			List<EntityObject>  objDetailContainer=this.Trans.RetrieveEntitys(objDetailEntity);
			ZZTrace.Debug(ZFILE_NAME,"UID08025A_POSTED.....11");
			
			if (objDetailContainer.Count==0)
			{
					throw new LogisticException("TM_NO","NotDetail",_Entity.TM_NO);
			}
			
			for (int i=0;i<objDetailContainer.Count;i++){
					TMRDTLMEntity objTMRDTLMEntity=(TMRDTLMEntity)objDetailContainer[i];
					ZZTrace.Debug(ZFILE_NAME,"UID08025A_POSTED.....2");
					ZZTrace.Debug(ZFILE_NAME,objTMRDTLMEntity.TM_DT);
					
					CriteriaRetrieve objValidateEntity=new CriteriaRetrieve(typeof(TRANCDMEntity));
					objCondition=objValidateEntity.NewCondition();
					objCondition.Equals("TRANS_CODE",objTMRHDTMEntity.TRANS_CODE);
		
					EntityObject objValidateObject=this.Trans.RetrieveEntity(objValidateEntity);
					TRANCDMEntity objTRANCDMEntity;
					if (objValidateObject!=null)
					{
						 objTRANCDMEntity=(TRANCDMEntity)objValidateObject;
					}else{
	        		throw new LogisticException("TRANS_CODE","DataNotFd",objTMRHDTMEntity.TRANS_CODE);
					}

					ZZTRANTBM  objZZTRANTBM   = new ZZTRANTBM();

					objZZTRANTBM.TRANS_CODE  = objTMRHDTMEntity.TRANS_CODE;
					objZZTRANTBM.TRANS_DATE  = objTMRHDTMEntity.TRANS_DATE;
					objZZTRANTBM.WH_CODE     = objTMRHDTMEntity.WH_CODE;
					objZZTRANTBM.WH_CODE     = objTMRHDTMEntity.WH_REFX;

          objZZTRANTBM.ZZLOGON_ID  = this.ZZLOGON_ID;
          objZZTRANTBM.ZZLOGON_SSD = this.ZZLOGON_SSD;

					objZZTRANTBM.UID_CODE     = ZFILE_NAME;
					objZZTRANTBM.TRANS_TP_CODE   = "TM";
					objZZTRANTBM.Trans = this.Trans;

					objZZTRANTBM.BAT_DT      = objTMRDTLMEntity.TM_DT;
					objZZTRANTBM.BAT_NO       = objTMRDTLMEntity.TM_NO;

					objZZTRANTBM.TRANS_QTY    = objTMRDTLMEntity.TRANS_QTY;
					objZZTRANTBM.TRANS_QTY2   = objTMRDTLMEntity.TRANS_QTY2;

					objZZTRANTBM.CCY_CODE     = objTMRDTLMEntity.CCY_CODE;
					objZZTRANTBM.XCHG_RATE    = objTMRDTLMEntity.XCHG_RATE;
					objZZTRANTBM.UNIT_PRICE   = objTMRDTLMEntity.UNIT_PRICE;

					objZZTRANTBM.REFX_NO       = objTMRDTLMEntity.REFX_NO;
					//objZZTRANTBM.DOC_NO       = objTMRDTLMEntity.DOC_NO;

					objZZTRANTBM.TRANS_UDFX1 = objTMRDTLMEntity.TRANS_UDFX1;
					objZZTRANTBM.TRANS_UDFX2 = objTMRDTLMEntity.TRANS_UDFX2;
					objZZTRANTBM.TRANS_UDFX3 = objTMRDTLMEntity.TRANS_UDFX3;
					objZZTRANTBM.TRANS_UDFX4 = objTMRDTLMEntity.TRANS_UDFX4;
					objZZTRANTBM.TRANS_UDFX5 = objTMRDTLMEntity.TRANS_UDFX5;
					objZZTRANTBM.TRANS_UDFX6 = objTMRDTLMEntity.TRANS_UDFX6;

					objZZTRANTBM.ITEM_NO     = objTMRDTLMEntity.ITEM_NO;

					ZZTrace.Debug(ZFILE_NAME,"UID08025A_POSTED.....A");

					objZZTRANTBM.DecreaseTransaction();

					objZZTRANTBM.TRANS_UDFX1 = objTMRDTLMEntity.TRANS_UDFN1;
					objZZTRANTBM.IncreaseTransaction();

					ZZTrace.Debug(ZFILE_NAME,"UID08025A_POSTED.....B");

					ZZTrace.Debug(ZFILE_NAME,"UID08025A_POSTED.....B");
					
			}
			ZZTrace.Debug(ZFILE_NAME,"UID08025A_POSTED.....");

				return _Entity;
		}

#region Field
			private CriteriaRetrieve objRetrieveEntity;
		private List<EntityObject>  objEntityContainer;
		private Condition        objCondition;
		private ZZDefault        objDefault      = new ZZDefault();
		private ZZDataPermission _DataPermission = new ZZDataPermission();
		private ZZDocsPermission _DocsPermission = new ZZDocsPermission();
		private ZZSetting        _Setting        = new ZZSetting();
		private XConvert         _Convert        = new XConvert();

#endregion

			const  string ZFILE_NAME   ="UID08025BM";
		const  string MUKI_EDITION ="MIN";

	}
}
